package net.lzzy.service;

import net.lzzy.entity.Comment;
import net.lzzy.entity.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service

public class CommentService {
    @Autowired
    CommentRepository commentRepository;
    public void SelectCommentById(Integer id){
        Optional<Comment> comment = commentRepository.findById(id);
        if(comment.isPresent())
            System.out.println(comment.get());
        else
            System.out.println("没有");
    }
    public List<Comment> SelectAllSortByAId(){
        return commentRepository.findAll(Sort.by(Sort.Direction.DESC,"aId"));
    }
    public List<Comment> SelectAllpage(int page, int size){
        Pageable pageable = PageRequest.of(page,size);
        return commentRepository.findAll(pageable).getContent();
    }

}
